<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
/* 
	企业微信class
*/
require_once __DIR__ . '/Wework.php';

class Weworkmsg extends Wework{
	
	protected $url_send = 'message/send';
	
	// 企业应用的id，整型
	public $agentid;
	
	public function __construct($option = array()){
		parent::__construct($option);
	}
	
	public function send($type, $option){
		if(!$this->access_token && !$this->get_accesstoken()){
			return false;
		}
		$data = [
			'msgtype' => $type,
			'agentid' => $option['agentid'] ? $option['agentid'] : $this->agentid
		];
		foreach($option as $key => $value){
			$data[$key] = $value;
		}
		$req = Http::request($this->url_api_host . $this->url_send . '?access_token=' . $this->access_token, json_encode($data), 'POST');
		if(!$req){
			return false;
		}
		$result = json_decode($req, true);
		if(!$result || $result['errcode']){
			$this->error = $result;
			return false;
		}
		return $result;
	}
	
}